package com.jkhan.springframework.beans.facroty.support;

import com.jkhan.springframework.beans.BeansException;
import com.jkhan.springframework.beans.facroty.config.BeanDefinition;

/**
 * @ClassName AbstractAutowireCapableBeanFactory
 * @Description AbstractAutowireCapableBeanFactory
 * @Author hjk
 * @Date 2022/11/27 17:09
 **/
public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFactory {

    @Override
    protected Object creatBean(String beanName, BeanDefinition beanDefinition) throws BeansException {
        Object bean = null;

        try {
            bean = beanDefinition.getBeanClass().newInstance();
        } catch (IllegalAccessException | InstantiationException e) {
            throw new BeansException("Instantiation of bean failed", e);
        }

        registerSingleton(beanName, bean);
        return bean;
    }

}
